<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<html:xhtml />
<script type="text/javascript">
    $(document).ready(function() {
        // Init help dialogs
        $("[id$=Desc]").dialog({
            autoOpen: false,
            width: 400,
            position: "right"
        });
        $("#ldPlotHelp").click(function() {
            $("#ldPlotDesc").dialog("open");
        });

        // 'DataTablize' the table
        $("#snpTable").dataTable({
            "bPaginate": true,
            "sPaginationType": "full_numbers",
            "bFilter": true,
            "bJQueryUI": true,
            "bAutoWidth": false,
            "aoColumns": [{"sType": "html"},
                {"bSortable": false},
                {"bSortable": false},
                {"bSearchable": false},
                {"bSearchable": false},
                {"bSearchable": false},
                {"bSearchable": false}]
        });
        $("table.geneOntology").dataTable({
            "bPaginate": true,
            "sPaginationType": "full_numbers",
            "bFilter": true,
            "bJQueryUI": true,
            "bAutoWidth": false,
            "aaSorting":[[5, 'asc']]
        });

        $("#links").accordion();
    });
</script>
<div id="geneSummary" class="content list summary">
    <html:form action="searchSubmit">
        <div class="input">
            <dl>
                <dt>Search Gene:</dt>
                <dd><html:text property="searchText" />&nbsp;<html:submit property="submitType" value="Search" /></dd>
            </dl>
            <html:hidden property="searchSelect" value="2" />
        </div>
    </html:form>
    <h2>
        <bean:write name="geneSummaryForm" property="geneName" />
    </h2>
    <div id="links" class="links">
        <logic:notEmpty name="geneSummaryForm" property="geneLinks">
            <h3>
                <a href="#">Gene Links</a>
            </h3>
            <ul>
                <logic:iterate id="link" name="geneSummaryForm" property="geneLinks">
                    <li>
                        <a href='<bean:write name="link" property="url"/>' target="new">
                            <bean:write name="link" property="name"/>
                        </a>
                    </li>
                </logic:iterate>
            </ul>
        </logic:notEmpty>
        <logic:notEmpty name="geneSummaryForm" property="pathwayLinks">
            <h3>
                <a href="#">Kegg Pathways</a>
            </h3>
            <ul>
                <logic:iterate id="link" name="geneSummaryForm" property="pathwayLinks">
                    <li>
                        <a href='<bean:write name="link" property="url" />' target="_blank" title='<bean:write name="link" property="title" />' >
                            <bean:write name="link" property="name" />
                        </a>
                    </li>
                </logic:iterate>
            </ul>
        </logic:notEmpty>
    </div>
    <div id="mainContent" class="input main list">
        <h3 class="ui-helper-reset ui-state-active ui-corner-all">
            General Information
        </h3>
        <dl>
            <dt>Gene:</dt>
            <dd><bean:write name="geneSummaryForm" property="geneName" /></dd>
            <dt>Gene Alias:</dt>
            <dd><bean:write name="geneSummaryForm" property="geneAliases" />&nbsp;</dd>
            <dt>Chromosome:</dt>
            <dd><bean:write name="geneSummaryForm" property="chromosome" /></dd>
            <dt>
                LD Plots:
                <span id="ldPlotHelp" class="ui-icon help ui-icon-info">&nbsp;&nbsp;&nbsp;&nbsp;</span>
            </dt>
            <dd>
                <a onclick="openLdPlot('<bean:write name="geneSummaryForm" property="geneName" />', 'CAPPS', 3);">CAPPS</a> |
                <a onclick="openLdPlot('<bean:write name="geneSummaryForm" property="geneName" />', 'SAGE', 4);">SAGE</a> |
                <a onclick="openLdPlot('<bean:write name="geneSummaryForm" property="geneName" />', 'SLSJ', 5);">SLSJ</a> |
                <a onclick="openLdPlot('<bean:write name="geneSummaryForm" property="geneName" />', 'Busselton', 6);">Busselton</a>
            </dd>
        </dl>
        <h3 class="ui-helper-reset ui-state-active ui-corner-all">
            SNPs
        </h3>
        <table id="snpTable" cellpadding="0" cellspacing="0" border="0" class="display">
            <thead>
                <tr>
                    <!-- GOTCHA: Manually adding 'ui-state-default' classes to match appearance.
                         NOTE: There were couple old forum threads that stated that dataTable cannot
                         handle multiple th's in a row. This table, with two th's in each column seems
                         to be working now. However, this might cause a problem in future changes. -->
                    <th colspan="3" class="ui-state-default">&nbsp;</th>
                    <th colspan="4" class="ui-state-default">Genotyping Status</th>
                </tr>
                <tr>
                    <th>RS number</th>
                    <th>Gene</th>
                    <th>Chromosome</th>
                    <logic:iterate id="cohort" name="geneSummaryForm" property="cohortList" length="4">
                        <th><bean:write name="cohort" property="name" /></th>
                    </logic:iterate>
                </tr>
            </thead>
            <tbody>
                <logic:iterate id="snpInfo" name="geneSummaryForm" property="snpList">
                    <tr>
                        <td>
                            <a href="<html:rewrite page="/snpSummary.do" />?rsNumber=<bean:write name="snpInfo" property="snp.rsNumber" />">
                                <bean:write name="snpInfo" property="snp.rsNumber" />
                            </a>
                        </td>
                        <td><bean:write name="geneSummaryForm" property="geneName" /></td>
                        <td><bean:write name="geneSummaryForm" property="chromosome" /></td>
                        <logic:iterate id="status" name="snpInfo" property="statusList" length="4">
                            <td>
                                <logic:notEmpty name="status">
                                    <logic:equal name="status" property="valid" value="true">
                                        <div title="Passed" class="ui-icon passed ui-icon-check" />
                                    </logic:equal>
                                    <logic:notEqual name="status" property="valid" value="true">
                                        <div title="Failed" class="ui-icon failed ui-icon-closethick" />
                                    </logic:notEqual>
                                </logic:notEmpty>
                                <logic:empty name="status">
                                    <div title="Not Available" class="ui-icon na ui-icon-help" />
                                </logic:empty>
                            </td>
                        </logic:iterate>
                    </tr>
                </logic:iterate>
            </tbody>
        </table>
        <h3 class="ui-helper-reset ui-state-active ui-corner-all">
            Gene Ontology Association Results
        </h3>
        <logic:iterate id="phenoEntry" name="geneSummaryForm" property="geneOntologyMap" type="java.util.Map.Entry">
            <h4>
                <bean:write name="phenoEntry" property="key.name" />
            </h4>
            <table cellpadding="0" cellspacing="0" border="0" class="display geneOntology">
                <thead>
                    <tr>
                        <th>Gene Ontology Category</th>
                        <logic:iterate id="cohort" name="geneSummaryForm" property="cohortList">
                            <th><bean:write name="cohort" property="name" /></th>
                        </logic:iterate>
                    </tr>
                </thead>
                <tbody>
                    <logic:iterate id="goEntry" name="phenoEntry" property="value" type="java.util.Map.Entry">
                        <tr>
                            <td><bean:write name="goEntry" property="key.name" /></td>
                            <logic:iterate id="cohortEntry" name="goEntry" property="value" type="java.util.Map.Entry">
                                <td>
                                    <logic:empty name="cohortEntry">
                                        <div title="Not Available" class="ui-icon na ui-icon-help" />
                                    </logic:empty>
                                    <logic:empty name="cohortEntry" property="value">
                                        <div title="Not Available" class="ui-icon na ui-icon-help" />
                                    </logic:empty>
                                    <logic:notEmpty name="cohortEntry" property="value">
                                        <bean:write name="cohortEntry" property="value" />
                                    </logic:notEmpty>
                                </td>
                            </logic:iterate>
                        </tr>
                    </logic:iterate>
                </tbody>
            </table>
        </logic:iterate>
    </div>
</div>
<tiles:insert name="ldPlotDesc" />
<tiles:insert name="ldPlotModal" />